SPB Git

Repository Public

route.ts 1.6 KB 25 lines typescript

1// Vrai-Prix — analyse multimodale : correction manuelle d'une inférence (origine conservée), puis recalcul déterministe du coût.2import { NextRequest, NextResponse } from "next/server";3import { AnalysisError, override } from "@/lib/cost/ai/service";4import { clientKey, rateLimit } from "@/lib/cost/cache";56export const runtime = "nodejs";78export async function PATCH(req: NextRequest, { params }: { params: Promise<{ uid: string }> }) {9  const { uid } = await params;10  if (!rateLimit(`ai-override:${clientKey(req)}`, 60, 60_000)) return NextResponse.json({ error: "Trop de requêtes." }, { status: 429 });11  let body: { analysisId?: string; field_path?: string; fieldPath?: string; new_value?: unknown; value?: unknown };12  try { body = await req.json(); } catch { return NextResponse.json({ error: "JSON invalide" }, { status: 400 }); }13  const fieldPath = body.field_path ?? body.fieldPath;14  const value = body.new_value ?? body.value;15  if (!body.analysisId || !fieldPath || value === undefined) return NextResponse.json({ error: "analysisId, field_path et new_value requis" }, { status: 400 });16  try {17    const v = override(body.analysisId, String(fieldPath).slice(0, 80), value, req.headers.get("x-session-id"));18    if (v.listingUid !== decodeURIComponent(uid)) return NextResponse.json({ error: "analyse d'une autre annonce" }, { status: 400 });19    return NextResponse.json(v, { headers: { "Cache-Control": "no-store" } });20  } catch (e) {21    if (e instanceof AnalysisError) return NextResponse.json({ error: e.message, code: e.code }, { status: e.status });22    return NextResponse.json({ error: (e as Error).message }, { status: 500 });23  }24}25
Files main
Menu

Theme